package com.tensquare.qa.service;

import com.tensquare.qa.dao.ProblemDao;
import com.tensquare.qa.pojo.Problem;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * & ProjectName：  tensquare-parent
 * & PackageName:   com.tensquare.qa.service
 * & Creation_Date： 2020/3/31 00:50
 * & Author：しの
 * ----------------------------------
 * & Description:
 */
@Service
public class ProblemService {

    @Autowired
    private ProblemDao problemDao;

    //1 查询最新回答问题列表
    public PageResult newlist(String labelid, int page, int size) {
        Page<Problem> problemPage = problemDao.findProblemsByLabelid(labelid, PageRequest.of(page - 1, size));
        return new PageResult(problemPage.getTotalElements(), problemPage.getContent());
    }

    //2 热门问题列表
    public PageResult hotlist(String labelid, int page, int size) {
        Page<Problem> problemPage = problemDao.findHotlistByLabelid(labelid, PageRequest.of(page - 1, size));
        return new PageResult(problemPage.getTotalElements(), problemPage.getContent());
    }
}
